home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / LabelButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  4.7 KB  |  235 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10.  
  11. public class LabelButton extends ButtonBase implements AlignStyle, BevelStyle {
  12.    public static final int INDENT_ZERO = 0;
  13.    public static final int INDENT_ONE = 1;
  14.    public static final int INDENT_TWO = 2;
  15.    protected String sLabelButton;
  16.    protected boolean showLabel;
  17.    private int alignStyle;
  18.    private int bevelStyle;
  19.    private Color color1;
  20.    private Color color2;
  21.    private Color textColor;
  22.    private Color borderedColor;
  23.    // $FF: renamed from: fm java.awt.FontMetrics
  24.    private FontMetrics field_0;
  25.    private int xTemp;
  26.    private int yTemp;
  27.    private int indent;
  28.    private boolean bOsFlag;
  29.  
  30.    public LabelButton() {
  31.       this("", 1, 2, Color.black, 0, true);
  32.    }
  33.  
  34.    public LabelButton(String var1, int var2, int var3) {
  35.       this(var1, var2, var3, Color.black, 0, true);
  36.    }
  37.  
  38.    public LabelButton(String var1, int var2, int var3, Color var4) {
  39.       this(var1, var2, var3, var4, 0, true);
  40.    }
  41.  
  42.    public LabelButton(String var1, int var2, int var3, int var4) {
  43.       this(var1, var2, var3, Color.black, var4, true);
  44.    }
  45.  
  46.    public LabelButton(String var1, int var2, int var3, Color var4, int var5, boolean var6) {
  47.       this.bOsFlag = false;
  48.       String var7 = System.getProperty("os.name");
  49.       if (!var7.startsWith("S") && !var7.startsWith("OSF")) {
  50.          this.bOsFlag = false;
  51.       } else {
  52.          this.bOsFlag = true;
  53.          ((Component)this).setFont(new Font("Dialog", 0, 10));
  54.       }
  55.  
  56.       this.sLabelButton = var1;
  57.       this.textColor = var4;
  58.       this.borderedColor = Color.black;
  59.       this.setBorderIndent(var5);
  60.       this.setAlignStyle(var2);
  61.       this.setBevelStyle(var3);
  62.       super.showFocus = true;
  63.    }
  64.  
  65.    public void setAlignStyle(int var1) {
  66.       this.alignStyle = var1;
  67.    }
  68.  
  69.    public int getAlignStyle() {
  70.       return this.alignStyle;
  71.    }
  72.  
  73.    public void setBevelStyle(int var1) {
  74.       this.bevelStyle = var1;
  75.       switch (var1) {
  76.          case 0:
  77.             this.color1 = Color.black;
  78.             this.color2 = Color.gray;
  79.             return;
  80.          case 1:
  81.             this.color1 = Color.gray;
  82.             this.color2 = Color.black;
  83.             return;
  84.          case 2:
  85.             this.color1 = this.borderedColor;
  86.             this.color2 = this.borderedColor;
  87.             return;
  88.          default:
  89.             this.color1 = this.color2 = null;
  90.       }
  91.    }
  92.  
  93.    public int getBevelStyle() {
  94.       return this.bevelStyle;
  95.    }
  96.  
  97.    public void setBorderIndent(int var1) {
  98.       if (var1 < 0) {
  99.          this.indent = 0;
  100.       } else if (var1 > 2) {
  101.          this.indent = 2;
  102.       } else {
  103.          this.indent = var1;
  104.       }
  105.    }
  106.  
  107.    public int getBorderIndent() {
  108.       return this.indent;
  109.    }
  110.  
  111.    public void setBorderedColor(Color var1) {
  112.       this.borderedColor = var1;
  113.       if (this.bevelStyle == 2) {
  114.          this.color1 = var1;
  115.          this.color2 = var1;
  116.       }
  117.  
  118.       ((Component)this).invalidate();
  119.    }
  120.  
  121.    public void setText(String var1) {
  122.       this.sLabelButton = var1;
  123.    }
  124.  
  125.    public String getText() {
  126.       return this.sLabelButton;
  127.    }
  128.  
  129.    public void setTextColor(Color var1) {
  130.       this.textColor = var1;
  131.    }
  132.  
  133.    public Color getTextColor() {
  134.       return this.textColor;
  135.    }
  136.  
  137.    public void setShowLabel(boolean var1) {
  138.       this.showLabel = var1;
  139.    }
  140.  
  141.    public boolean getShowLabel() {
  142.       return this.showLabel;
  143.    }
  144.  
  145.    public void paint(Graphics var1) {
  146.       if (super.showFocus) {
  147.          Dimension var2 = ((Component)this).size();
  148.          Rectangle var3 = ((Component)this).bounds();
  149.          Color var4 = var1.getColor();
  150.          if (this.color1 != null) {
  151.             this.yTemp = 1 + this.indent;
  152.          } else {
  153.             this.yTemp = 1;
  154.          }
  155.  
  156.          this.field_0 = ((Component)this).getFontMetrics(((Component)this).getFont());
  157.          this.yTemp = (var3.height - this.yTemp + this.field_0.getAscent()) / 2;
  158.          switch (this.alignStyle) {
  159.             case 0:
  160.                if (this.bevelStyle == 2) {
  161.                   this.xTemp = 4;
  162.                } else {
  163.                   this.xTemp = 8;
  164.                }
  165.                break;
  166.             case 1:
  167.                this.xTemp = (var3.width - this.field_0.stringWidth(this.sLabelButton)) / 2;
  168.                break;
  169.             case 2:
  170.                this.xTemp = var3.width - this.field_0.stringWidth(this.sLabelButton);
  171.                if (this.bevelStyle == 2) {
  172.                   this.xTemp -= 6;
  173.                } else {
  174.                   this.xTemp -= 10;
  175.                }
  176.          }
  177.  
  178.          if ((!super.inButton || !super.showFocus) && !this.showLabel) {
  179.             if (!super.inButton && super.showFocus) {
  180.                var1.setColor(((Component)this).getBackground());
  181.                var1.drawRect(0, 0, var2.width - 1, var2.height - 1);
  182.                var1.fillRect(this.xTemp, this.yTemp - this.field_0.getAscent(), this.field_0.stringWidth(this.sLabelButton), this.field_0.getAscent());
  183.             }
  184.          } else {
  185.             var1.setColor(super.inButton ? Color.gray : ((Component)this).getBackground());
  186.             var1.drawRect(0, 0, var2.width - 1, var2.height - 1);
  187.             var1.setColor(this.textColor);
  188.             var1.drawString(this.sLabelButton, this.xTemp, this.yTemp);
  189.          }
  190.  
  191.          if (super.doInfoTip) {
  192.             ((ButtonBase)this).drawInfoTip();
  193.          }
  194.  
  195.       }
  196.    }
  197.  
  198.    public Dimension preferredSize() {
  199.       Dimension var1 = ((Component)this).size();
  200.       Dimension var2 = this.minimumSize();
  201.       return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
  202.    }
  203.  
  204.    public Dimension minimumSize() {
  205.       Dimension var1 = new Dimension(18, 10);
  206.       Font var2 = ((Component)this).getFont();
  207.       if (var2 == null) {
  208.          if (this.bOsFlag) {
  209.             var1.height = 29;
  210.          }
  211.       } else {
  212.          this.field_0 = ((Component)this).getFontMetrics(var2);
  213.          var1.width = this.field_0.stringWidth(this.sLabelButton) + 18;
  214.          var1.height = this.field_0.getHeight() + 10;
  215.          if (this.bOsFlag && var1.height < 29) {
  216.             var1.height = 29;
  217.          }
  218.       }
  219.  
  220.       return var1;
  221.    }
  222.  
  223.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  224.       super.reshape(var1, var2, var3, var4);
  225.       if (!((Component)this).isValid()) {
  226.          ((Component)this).repaint();
  227.       }
  228.  
  229.    }
  230.  
  231.    public void update(Graphics var1) {
  232.       this.paint(var1);
  233.    }
  234. }
  235.